package com.codename1.samples;


import static com.codename1.ui.CN.*;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Dialog;
import com.codename1.ui.Label;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.io.Log;
import com.codename1.ui.Toolbar;
import java.io.IOException;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.io.NetworkEvent;
import com.codename1.ui.AutoCompleteTextField;
import com.codename1.ui.Container;
import com.codename1.ui.Tabs;
import com.codename1.ui.layouts.BorderLayout;

/**
 * This file was generated by <a href="https://www.codenameone.com/">Codename One</a> for the purpose 
 * of building native mobile applications using Java.
 */
public class AutocompleteInTabsTest {

    private Form current;
    private Resources theme;

    public void init(Object context) {
        // use two network threads instead of one
        updateNetworkThreadCount(2);

        theme = UIManager.initFirstTheme("/theme");

        // Enable Toolbar on all Forms by default
        Toolbar.setGlobalToolbar(true);

        // Pro only feature
        Log.bindCrashProtection(true);

        addNetworkErrorListener(err -> {
            // prevent the event from propagating
            err.consume();
            if(err.getError() != null) {
                Log.e(err.getError());
            }
            Log.sendLogAsync();
            Dialog.show("Connection Error", "There was a networking error in the connection to " + err.getConnectionRequest().getUrl(), "OK", null);
        });        
    }
    
    public void start() {
        if(current != null){
            current.show();
            return;
        }
        
        Tabs tabs = new Tabs();
        Container tabsContainer1 = new Container(new BorderLayout());
        Container tabsContainer2 = new Container(new BorderLayout());

        Form hi = new Form("Popup test");

        AutoCompleteTextField autocompleteTab1 = new
        AutoCompleteTextField("1", "2", "3", "11", "22", "33");

        //autocompleteTab1.setMinimumLength(1); 

        AutoCompleteTextField autocompleteTab2 = new
        AutoCompleteTextField("1", "2", "3", "4", "11", "22", "33", "44");

        autocompleteTab2.setMinimumLength(1); 
        // pop up appears to be
        //drawn semi off screen and
        // see attached screenshot in email

        tabsContainer1.add(BorderLayout.CENTER, autocompleteTab1);
        tabs.addTab("working tab", tabsContainer1);

        tabsContainer2.add(BorderLayout.CENTER, autocompleteTab2);
        tabs.addTab("failing tab", tabsContainer2);

        hi.add(tabs);

hi.show();
    }

    public void stop() {
        current = getCurrentForm();
        if(current instanceof Dialog) {
            ((Dialog)current).dispose();
            current = getCurrentForm();
        }
    }
    
    public void destroy() {
    }

}
